package com.jeesite.modules.my.web;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.my.entity.MyUsers;
import com.jeesite.modules.my.service.MyUsersService;

/**
 * my_usersController
 * @author ccz
 * @version 2025-03-20
 */
@Controller
@RequestMapping(value = "${adminPath}/my/myUsers")
public class MyUsersController extends BaseController {

	@Autowired
	private MyUsersService myUsersService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public MyUsers get(String id, boolean isNewRecord) {
		return myUsersService.get(id, isNewRecord);
	}

	/**
	 * 管理主页
	 */
	@RequiresPermissions("my:myUsers:view")
	@RequestMapping(value = "index")
	public String index(MyUsers myUsers, Model model) {
		model.addAttribute("myUsers", myUsers);
		return "modules/my/myUsersIndex";
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("my:myUsers:view")
	@RequestMapping(value = {"list", ""})
	public String list(MyUsers myUsers, Model model) {
		model.addAttribute("myUsers", myUsers);
		return "modules/my/myUsersList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("my:myUsers:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<MyUsers> listData(MyUsers myUsers, HttpServletRequest request, HttpServletResponse response) {
		myUsers.setPage(new Page<>(request, response));
		Page<MyUsers> page = myUsersService.findPage(myUsers);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("my:myUsers:view")
	@RequestMapping(value = "form")
	public String form(MyUsers myUsers, Model model) {
		model.addAttribute("myUsers", myUsers);
		return "modules/my/myUsersForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("my:myUsers:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated MyUsers myUsers) {
		myUsersService.save(myUsers);
		return renderResult(Global.TRUE, text("保存my_users成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("my:myUsers:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(MyUsers myUsers) {
		myUsersService.delete(myUsers);
		return renderResult(Global.TRUE, text("删除my_users成功！"));
	}


	// 根据地区ID查询用户
	@RequestMapping("findByRegionId")
	@GetMapping
	public List<MyUsers> findByRegionId(@RequestParam String regionId) {
		return myUsersService.findByRegionId(regionId);
	}


	/*@GetMapping
	public List<Map<String, Object>> getTreeData(@RequestParam(required = false) String parentCode) {
		List<Map<String, Object>> data = myUsersService.getTreeData(parentCode);
		return data;
	}*/
}